/**
 * @author林间有风Lin
 * @description Virtual DOM描述
    <section class='???' id='cawd' onClick={this.ok}>
        <p>
            <div1>
                awd
                <h1>1212</h1>
            </div1>
        </p>
    </section>
 */

const createElement = (tag, attr, ...children) => {
    const keys = attr ? Object.keys(attr) : []
    const originTag = tag
    const child = children.length

    if (tag) {
        tag = `<${originTag}`
        keys.forEach(item => {
            if (/^[on]/.test(item)) {
                // 走事件
            } else {
                tag += ` ${item}=${attr[item]}`
            }
        })
        
        if (child === 1 && typeof children[0] === 'string'){
            tag += `>${children}</${originTag}>`
        }else{
            tag += `>`
            Array.from(children).forEach(item => {
                tag += `${item}`
            })
        }
    }
    return tag  
}

export { createElement }